#include<iostream>
#include<queue>
using namespace std;

bool arr[1000][1000]={false};
int dx[4] = {0,1,0,-1};
int dy[4] = {1,0,-1,0};

struct location
{
    int x, y, step;

    location() {
        x = y = step = 0;
    }
} start;

int main() {
    int n, m, k;
    cin >> n >> m;
    for (int i=0; i<n; i++) {
        for (int j=0; j<m; j++) {
            char temp;
            cin >> temp;
            if (temp == '1')  arr[i][j] = true;
        }
    }

    cin >> k;
    for (int ii=0; ii<k; ii++) {
        int x1, y1, x2, y2;
        bool flag = false, v[1000][1000] = {false};
        queue<location> q;

        cin >> x1 >> y1 >> x2 >> y2;
        if (x1 == x2 && y1 == y2) {
            cout << 0 << endl;
            continue;
        }
        start.x = x1 - 1;
        start.y = y1 - 1;
        x2--;
        y2--;

        // BFS区域
        q.push(start);
        v[start.x][start.y] = true;
        while(!q.empty()) {
            if(flag) break;
            for (int i=0; i<4; i++) {
                location lo = q.front();
                int xx = lo.x + dx[i];
                int yy = lo.y + dy[i];

                if (xx < 0 || yy < 0 || xx >= n || yy >= m ||
                        v[xx][yy] || !arr[xx][yy]) continue;
                if (xx == x2 && yy == y2) {
                    cout << lo.step + 1 << endl;
                    flag = true;
                    break;
                }
                lo.x = xx;
                lo.y = yy;
                lo.step++;

                q.push(lo);
                v[xx][yy] = true;
            }
            q.pop();
        }
        if (!flag)  cout << "Impossible" << endl;
    }
    return 0;
}
